home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / directoryopus4 / dopus4_src / library / dos_exec.c < prev    next >
C/C++ Source or Header  |  2000-03-11  |  4KB  |  134 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32.  
  33. __saveds DoSendPacket(register struct MsgPort *port __asm("a0"),
  34.     register int action __asm("d0"),
  35.     register ULONG *args __asm("a1"),
  36.     register int nargs __asm("d1"))
  37. {
  38.     struct StandardPacket *packet;
  39.     struct MsgPort *repport;
  40.     struct Process *myproc;
  41.     int count,res1,a;
  42.     ULONG *pargs;
  43.  
  44.     myproc=(struct Process *)FindTask(NULL);
  45.     if (!(packet=AllocMem(sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR)))
  46.         return(0);
  47.     if (!(repport=LCreatePort(NULL,0))) {
  48.         FreeMem(packet,sizeof(struct StandardPacket));  
  49.         return(0);
  50.     }
  51.  
  52.     packet->sp_Msg.mn_Node.ln_Name=(char *)&(packet->sp_Pkt);
  53.     packet->sp_Pkt.dp_Link=&(packet->sp_Msg);
  54.     packet->sp_Pkt.dp_Port=repport;
  55.     packet->sp_Pkt.dp_Type=action;
  56.  
  57.     pargs=(ULONG *)&(packet->sp_Pkt.dp_Arg1);
  58.     if (nargs>7) nargs=7;
  59.     for (count=0;count<nargs;count++) pargs[count]=args[count];
  60.  
  61.     PutMsg(port,(struct Message *)packet);
  62.     WaitPort(repport);
  63.     GetMsg(repport);
  64.  
  65.     res1=packet->sp_Pkt.dp_Res1;
  66.     a=packet->sp_Pkt.dp_Res2;
  67.     FreeMem(packet,sizeof(struct StandardPacket));
  68.     LDeletePort(repport);
  69.     if (myproc) myproc->pr_Result2=a;
  70.     return(res1);   
  71. }
  72.  
  73. ULONG __saveds DoAllocRemember(register struct DOpusRemember **key __asm("a0"),
  74.     register ULONG size __asm("d0"),
  75.     register ULONG type __asm("d1"))
  76. {
  77.     struct DOpusRemember *node,*cur;
  78.  
  79.     size+=sizeof(struct DOpusRemember);
  80.     if (!(node=AllocMem(size,type))) return(NULL);
  81.     node->next=NULL;
  82.     if ((*key)==NULL) {
  83.         node->current=node;
  84.         (*key)=node;
  85.     }
  86.     else {
  87.         cur=(*key)->current;
  88.         (*key)->current=node;
  89.         cur->next=node;
  90.     }
  91.     node->size=size;
  92.     size=(ULONG)node+sizeof(struct DOpusRemember);
  93.     return((ULONG)size);
  94. }
  95.  
  96. void __saveds DoFreeRemember(register struct DOpusRemember **key __asm("a0"))
  97. {
  98.     struct DOpusRemember *node,*cur;
  99.  
  100.     if ((*key)==NULL) return;
  101.     node=(*key);
  102.     while (node) {
  103.         cur=node->next;
  104.         FreeMem(node,node->size);
  105.         node=cur;
  106.     }
  107.     (*key)=NULL;
  108. }
  109.  
  110. void __saveds DoFreeRemEntry(register struct DOpusRemember **key __asm("a0"),
  111.     register char *pointer __asm("a1"))
  112. {
  113.     struct DOpusRemember *node,*last=NULL;
  114.  
  115.     if ((*key)==NULL) return;
  116.     pointer-=sizeof(struct DOpusRemember);
  117.  
  118.     node=(*key);
  119.     while (node) {
  120.         if (node==(struct DOpusRemember *)pointer) {
  121.             if (last) last->next=node->next;
  122.             if ((*key)->current==node) (*key)->current=last;
  123.             if (node==(*key)) {
  124.                 last=(*key)->current;
  125.                 if (((*key)=node->next)) (*key)->current=last;
  126.             }
  127.             FreeMem(node,node->size);
  128.             break;
  129.         }
  130.         last=node;
  131.         node=node->next;
  132.     }
  133. }
  134.